//
//  SRSportDetailView.m
//  SportRing
//
//  Created by elwin on 10/29/14.
//  Copyright (c) 2014 HotOne. All rights reserved.
//

#import "SRSportDetailView.h"


@interface SRSportDetailView()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, weak)IBOutlet UITableView *srSportDetailTableView;
@property (nonatomic, weak)IBOutlet SRSportHeaderView *srSportHeaderView;

@property (nonatomic, strong)NSArray *sportTableDataSource;

@end

@implementation SRSportDetailView

- (void)awakeFromNib{
    [super awakeFromNib];
    [self setTableHeaderView];
    [self.srSportHeaderView setBackgroundColor:[UIColor colorWithRed:116.0/255.0 green:169.0/255.0 blue:31.0/255.0 alpha:1.0]];
    [self.srSportDetailTableView setBackgroundColor:[UIColor colorWithRed:246.0/255.0 green:245.0/255.0 blue:240.0/255.0 alpha:1.0]];
}

- (void)SRSportDetailViewDataWithSportHeaderModel:(SRSportHeaderViewModel *)headerModel sportArray:(NSArray *)sportArray
{
    [_srSportHeaderView setSRSportHeaderViewDataWithModel:headerModel];
    _sportTableDataSource = sportArray;
    [_srSportDetailTableView reloadData];
}

- (void)setTableHeaderView
{
    UIImageView *hearderView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.srSportDetailTableView.frame.size.width, 40)];
    hearderView.backgroundColor = [UIColor clearColor];
    UIImageView *clockImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sport_detail_clock"]];
    [clockImageView setFrame:CGRectMake(50, 9, clockImageView.frame.size.width, clockImageView.frame.size.height)];
    [hearderView addSubview:clockImageView];
    self.srSportDetailTableView.tableHeaderView = hearderView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [_sportTableDataSource count]>0?[_sportTableDataSource count]:0;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
   SRSportDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SRSportDetailTableViewCell"];
    
    if (_sportTableDataSource && [_sportTableDataSource count] > 0)
    {
        [cell setSRSportDetailTableViewCellDataWithSRSportDetailTableViewCellModel:(SRSportDetailTableViewCellModel *)[_sportTableDataSource objectAtIndex:indexPath.row]];
    }
    
    return cell;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
